package utilJdbc;

import java.sql.*;

public class jdbc {
    public String yanzheng(String id) {
        Connection conn = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        String URL = "jdbc:mysql://localhost:3306/students?serverTimezone=UTC";
        String USER = "root";
        String PASS = "root";
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            conn = DriverManager.getConnection(URL, USER, PASS);
            preparedStatement = conn.prepareStatement("select * from users where userid=?");
            preparedStatement.setObject(1,id);
            resultSet = preparedStatement.executeQuery();
            if(resultSet.next()) {
                String pwd = resultSet.getString("userpwd");
                return pwd;
            } else
                return "";
        } catch (SQLException | ClassNotFoundException e) {
            e.printStackTrace();
        }finally {
            try {
                if(resultSet!=null)
                    resultSet.close();
                if(preparedStatement!=null)
                    preparedStatement.close();
                if(conn!=null)
                    conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return "";
    }
}
